<html>
<head><meta charset="utf-8"><title>a help about learning compiler structure · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/a.20help.20about.20learning.20compiler.20structure.html">a help about learning compiler structure</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217017571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/a%20help%20about%20learning%20compiler%20structure/near/217017571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hossein dindar <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/a.20help.20about.20learning.20compiler.20structure.html#217017571">(Nov 17 2020 at 15:30)</a>:</h4>
<p>Hi guys, sorry I guess I should not ask this question here but  I am a little confused about compiler structure, I decided to work on rust compiler since the last 2 months ago to make a contribution to open source and also learn how we write a compiler from scratch.<br>
I could fix two issues (of course by asking for help not just by myself), then I decided to work on an issue that is related to parser about giving better diagnostics on some cases, and then I started it by debugging but I could not get success, because some tests fail, so I decided to read the lexer and parser codes from scratch and see what happens when we execute any program and see what is the path, but now I am a little hopeless that I can't do it, because I feel I am lost between many functions that each one calls many other functions and I can't understand completely what happens in each phase, so I wanted to ask you guys that do you think it is better that I first create a compiler by myself and then return back to working on rust,<br>
or my current approach is correct?</p>



<a name="217030648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/a%20help%20about%20learning%20compiler%20structure/near/217030648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/a.20help.20about.20learning.20compiler.20structure.html#217030648">(Nov 17 2020 at 16:57)</a>:</h4>
<p>You don't need to create your own compiler from scratch just to understand how compilers work. That's certainly an approach, and it could be fun, but it's not the only way to learn compilers.</p>



<a name="217030823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/a%20help%20about%20learning%20compiler%20structure/near/217030823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/a.20help.20about.20learning.20compiler.20structure.html#217030823">(Nov 17 2020 at 16:58)</a>:</h4>
<p>I would tend to suggest a more incremental approach, given what you're trying to do. If you'd like to learn how rust handles diagnostics and suggestions, you might look at an existing code suggestion for bad code, and see how rust generates that. In particular, look at the mechanisms for marking spans and similar.</p>



<a name="217030958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/a%20help%20about%20learning%20compiler%20structure/near/217030958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/a.20help.20about.20learning.20compiler.20structure.html#217030958">(Nov 17 2020 at 16:59)</a>:</h4>
<p>You could also try experiments within the rust compiler, such as giving out a random suggestion within a bit of existing code, just to confirm that you know how that infrastructure works.</p>



<a name="217031675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/a%20help%20about%20learning%20compiler%20structure/near/217031675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hossein dindar <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/a.20help.20about.20learning.20compiler.20structure.html#217031675">(Nov 17 2020 at 17:05)</a>:</h4>
<p>yeah I agree, it is a good approach, thanks for your suggestion <span aria-label="pray" class="emoji emoji-1f64f" role="img" title="pray">:pray:</span></p>



<a name="217039187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/a%20help%20about%20learning%20compiler%20structure/near/217039187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/a.20help.20about.20learning.20compiler.20structure.html#217039187">(Nov 17 2020 at 18:01)</a>:</h4>
<p>I don't want to discourage the "experiment to learn" approach that you started down; I would just highly recommend more incremental experiments with quick results each time.</p>



<a name="217040121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/a%20help%20about%20learning%20compiler%20structure/near/217040121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Ellis O&#x27;Riley Jr. <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/a.20help.20about.20learning.20compiler.20structure.html#217040121">(Nov 17 2020 at 18:07)</a>:</h4>
<p>Josh, I also think that’s a great approach and want to thank you for sharing.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>